<?php
class uploadAction extends runAction {
	
	public function upload() {
		foreach ( $_FILES as $k => $v ) {
			if ($v ['size'] != 0) {
				$go = 1;
				break;
			}
		}
		
		if ($go == 1) {
			
			$updir = $GLOBALS ['uploaddir']==''?$_COOKIE ['uploaddir']:$GLOBALS ['uploaddir'];
			
			$dir = RP . 'upload/' . $updir . '/' . $GLOBALS ['id'] . '/';
			
			$arr = array();
			foreach ( $_FILES as $k => $v ) {
				
				if (substr ( strtolower ( $v['name'] ), -3 ) == 'zip') {
					$arr[] = $dir . iconv ( 'UTF-8', 'GBK', $v ['name'] );
				}
			}
			
			import ( 'app.ORG.UploadFile' );
			
			$upload = new UploadFile ();
			//设置上传文件大小
			$upload->maxSize = (int)ini_get('upload_max_filesize')*1024*1024;
			//设置上传文件类型
			$upload->allowExts = array ('jpg', 'jpeg', 'gif', 'png', 'zip', 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx' , 'flv' ,'psd','txt','bmp','rar','mp4');
			//设置附件上传目录
			$upload->savePath = RP.'upload/' . $updir . '/' . $GLOBALS ['id'] . '/';
			//设置上传文件名
			$upload->saveRule = '';
			//删除原图
			$upload->thumbRemoveOrigin = false;
			/*dump($_COOKIE);
			echo $upload->savePath;
			dump($upload->upload ());
			exit;*/
			if (! $upload->upload ()) {
					
				//捕获上传异常
				$this->error ( $upload->getErrorMsg () );
			}
			
			if(count($arr)>0){
				import ( 'app.ORG.zip' );
				$z = new unzip ();
				foreach ($arr as $v){
					$z->Extract ( $v, $dir.'zip' );
				}
			}
		
		}
		
	}
	

	
	public function f_upload($t,$dir) {
		
		if(empty($t)){
			echo '';
		}
		
		$updir = $GLOBALS ['uploaddir']==''?$_COOKIE ['uploaddir']:$GLOBALS ['uploaddir'];
		
		import ( 'app.ORG.UploadFile' );
		
		$upload = new UploadFile ();
		//设置上传文件大小
		$upload->maxSize = (int)ini_get('upload_max_filesize')*1024*1024;
		//设置上传文件类型
		$upload->allowExts = array ('jpg', 'jpeg', 'gif', 'png', 'zip', 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx' , 'flv' ,'psd','txt','bmp','rar','mp4');
		//设置附件上传目录
		$upload->savePath = RP.'upload/' . $updir.'/'.$dir.'/';
		//设置上传文件名
		$upload->saveRule = '';
		//删除原图
		$upload->thumbRemoveOrigin = false;
		//echo $_COOKIE ['uploaddir'];exit;
		if ( $upload->upload ()) {
			//chmod($upload->savePath,0740);
			//捕获上传异常
			echo '1';
		}else {
			echo '上传错误';
		}
	
	}
}
?>